<?php

require_once 'const/DBConst.php';

class Application_Model_OrderMapper {

    public static function insert($order) {
        $db = Zend_Registry::get("database");
        $date = array(
            C_ACCOUNT_ID => $order->getAccountID(),
            C_PRODUCT_ID => $order->getProductID(),
            C_NUM => $order->getCount()
        );
        $db->insert(T_ORDER, $date);
        return $db->lastInsertId();
    }

    public static function fetchAll() {
        $db = Zend_Registry::get("database");
        $result = $db->fetchAll("SELECT ORDERS.ID, PRODUCT.PRICE, ORDERS.NUM, PRODUCT.NAME, ACCOUNT.EMAIL FROM ORDERS, PRODUCT, ACCOUNT WHERE ORDERS.PRODUCT_ID = PRODUCT.ID AND ORDERS.ACCOUNT_ID= ACCOUNT.ID");
        return $result;
    }

    public static function fetchByType($accountID) {
        $db = Zend_Registry::get("database");
        $result = $db->fetchAll("SELECT ORDERS.ID, PRICE, ORDERS.NUM, NAME FROM ORDERS, PRODUCT WHERE ORDERS.PRODUCT_ID = PRODUCT.ID AND ORDERS.ACCOUNT_ID=" . $accountID);
        return $result;
    }

}

